#ifndef __COMMON_H__
#define __COMMON_H__

#define BUF_SIZE 512

#define IPV4_STR_LENGTH 16
#define DOMAIN_STR_LENGTH 64

#define INVALID_SOCKET -1
#define SOCKET_ERROR -1

#define DNS_DEFAULT_PORT 53

typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;

/* Close a socket and set it to INVALID_SOCKET */
void close_socket(SOCKET * socket);

/* Print a system error message (perror) with the given function name,
 * properly close all the given sockets and exit with errno */
void exit_syserr(char * func_name, SOCKET * socket, ...);

/* Print an error message, properly close all the given sockets
 * and exit with the given error code */
void exit_runerr(char * err_msg, int err_code, SOCKET * socket, ...);

#endif
